//售后单退款详情
import React from 'react'
import GoBack from '@/components/TheGoBack'
import RefundStep from './step'
import RefundInfo from './info'
import RefundServiceTable from './serviceTable'
import RefundLinkTable from './linkedTable'
import { callSalesReturnOrderDetail } from '@/request/callOrder/afterSaleOrder'
export default class RefundDetails extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      refundInfo: null, //数据信息
      salesReturnId: '',//售后单id
    }
  }
  componentDidMount() {
    let { id } = this.props.match.params
    if (id) {
      this.setState({
        salesReturnId: id
      }, () => { this.getData(id) })
    }
  }
  //订单详情数据
  getData = async (salesReturnId) => {
    let res = await callSalesReturnOrderDetail(salesReturnId)
    if (res.code === 0 && res.data) {
      this.setState({ refundInfo: res.data }, () => {
        this.RefundStepRef.getData() //进度数据
        this.RefundInfoRef.getData() //信息数据
        this.RefundServiceTableRef.getData() //服务信息
        this.RefundLinkTableRef.getData() //关联订单
      })
    }
  }

  render() {
    const { refundInfo, salesReturnId } = this.state
    return (
      <div className='p-layout-box'>
        <GoBack history={this.props.history} title='售后单详情'></GoBack>
        {
          refundInfo && <div>
            <RefundStep ref={(ref) => this.RefundStepRef = ref} info={refundInfo} history={this.props.history} getRequest={() => { this.getData(salesReturnId) }}></RefundStep>
            <RefundInfo ref={(ref) => this.RefundInfoRef = ref} info={refundInfo} getRequest={() => { this.getData(salesReturnId) }}></RefundInfo>
            <RefundServiceTable ref={(ref) => this.RefundServiceTableRef = ref} info={refundInfo} history={this.props.history} getRequest={() => { this.getData(salesReturnId) }}></RefundServiceTable>
            <RefundLinkTable ref={(ref) => this.RefundLinkTableRef = ref} info={refundInfo} history={this.props.history} getRequest={() => { this.getData(salesReturnId) }}></RefundLinkTable>
          </div>
        }
      </div>
    )
  }
}